package com.tool.util;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;

public class TemplateUtil {
	private static final Configuration cfg = new Configuration();

	static {
		try {
			ResourceLoader resourceLoader = new DefaultResourceLoader();

			org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:/templates/");

			cfg.setDirectoryForTemplateLoading(resource.getFile());
			cfg.setObjectWrapper(new DefaultObjectWrapper());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Template getTemplate(String name) throws Exception {
		return cfg.getTemplate(name);
	}
}